package com.ruoyi.system.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.system.domain.AlpContractDetail;
import com.ruoyi.system.service.IAlpContractDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.AlpContractStageMapper;
import com.ruoyi.system.domain.AlpContractStage;
import com.ruoyi.system.service.IAlpContractStageService;
import com.ruoyi.common.core.text.Convert;

/**
 * 合同阶段表Service业务层处理
 * 
 * @author zhangjun
 * @date 2020-02-13
 */
@Service
public class AlpContractStageServiceImpl implements IAlpContractStageService 
{
    @Autowired
    private AlpContractStageMapper alpContractStageMapper;

    @Autowired
    private IAlpContractDetailService alpContractDetailService;

    /**
     * 查询合同阶段表
     * 
     * @param stageId 合同阶段表ID
     * @return 合同阶段表
     */
    @Override
    public AlpContractStage selectAlpContractStageById(Long stageId)
    {
        return alpContractStageMapper.selectAlpContractStageById(stageId);
    }

    @Override
    public List<AlpContractStage> selectAlpContractStageByContractId(Long contractId) {
        return alpContractStageMapper.selectAlpContractStageByContractId(contractId);
    }

    /**
     * 查询合同阶段表列表
     * 
     * @param alpContractStage 合同阶段表
     * @return 合同阶段表
     */
    @Override
    public List<AlpContractStage> selectAlpContractStageList(AlpContractStage alpContractStage)
    {
        return alpContractStageMapper.selectAlpContractStageList(alpContractStage);
    }

    /**
     * 新增合同阶段表
     * 
     * @param alpContractStage 合同阶段表
     * @return 结果
     */
    @Override
    public int insertAlpContractStage(AlpContractStage alpContractStage)
    {
        return alpContractStageMapper.insertAlpContractStage(alpContractStage);
    }

    public long selectMaxStageNo(Long contractId) {
        return alpContractStageMapper.selectMaxStageNo(contractId);
    }
    /**
     * 修改合同阶段表
     * 
     * @param alpContractStage 合同阶段表
     * @return 结果
     */
    @Override
    public int updateAlpContractStage(AlpContractStage alpContractStage)
    {
        return alpContractStageMapper.updateAlpContractStage(alpContractStage);
    }

    /**
     * 删除合同阶段表对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteAlpContractStageByIds(String ids)
    {
        return alpContractStageMapper.deleteAlpContractStageByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除合同阶段表信息
     * 
     * @param stageId 合同阶段表ID
     * @return 结果
     */
    @Override
    public int deleteAlpContractStageById(Long stageId)
    {
        return alpContractStageMapper.deleteAlpContractStageById(stageId);
    }

    @Override
    public Map<String,String> getStageDetail(Long stageId) {
        AlpContractDetail contract = alpContractDetailService.selectAlpContractByStageId(stageId);
        AlpContractStage stage = selectAlpContractStageById(stageId);

        Map<String,String> alpDetail = new HashMap<>();

        alpDetail.put("contractId",contract.getContractId().toString());
        alpDetail.put("contractNo", contract.getContractNo());
        alpDetail.put("contractName", contract.getContractName());
        alpDetail.put("stageId",stageId.toString());
        alpDetail.put("stageName", stage.getStageName());

        return alpDetail;
    }
}
